package com.jason.campusinn;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Toast;

import com.jason.campusinn.view.LoadingDialog;
import com.lidroid.xutils.DbUtils;


/**
 * 所有Fragment的基类
 */
public abstract class BaseFragment extends Fragment {

	protected Activity mActivity;
	protected Context mContext;
	protected View mView;

    /**
     * 全局DbUtils对象
     */
    protected DbUtils mDbUtils;

	/**
	 * 窗口管理器
	 */
	protected WindowManager mWindowManager;

    /** loadingDialog */
    protected LoadingDialog mLoadingDialog;


	/**fragment是否可见*/
	protected boolean isVisible = false;
//    private Toast mToast;

	public BaseFragment() {

	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		mActivity = activity;
		mContext = activity;
        mDbUtils = CampusInnApp.dbUtils;
        mLoadingDialog = new LoadingDialog(mContext);
	}

	@Override
	public void onDetach() {
		super.onDetach();
		mActivity = null;
		mContext = null;
		mWindowManager = null;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return mView;
	}

	@Override
	public void onResume() {
		super.onResume();
	}
    @Override
    public void onPause() {
        super.onPause();
    }

	/**
	 * 显示Toast提示
	 * 
	 * @param text
	 */
	protected void showToast(String text) {
//        if (mToast != null){
//            mToast.setText(text);
//        } else {
//            mToast = Toast.makeText(mContext, text, Toast.LENGTH_SHORT);
//        }
//        mToast.show();
		if( mContext != null ){

			Toast.makeText(mContext, text, Toast.LENGTH_SHORT).show();
		}
	}


//	@Override
//	public void setUserVisibleHint(boolean isVisibleToUser) {
//		super.setUserVisibleHint(isVisibleToUser);
//
//		if(getUserVisibleHint()) {
//			isVisible = true;
//		} else {
//			isVisible = false;
//		}
//	}

	@Override
	public void onHiddenChanged(boolean hidden) {
		super.onHiddenChanged(hidden);
	}
	

}
